/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import java.util.Vector;

import Models.NhanVien_Model;
import Models.KhuVuc_Model;
import Models.Ban_Model;
import Models.DatBan_Model;
import Models.NhatKyHT_Model;
import Beans.NhanVien;

/**
 *
 * @author Venus
 */
public class DatBan_Controller extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        try {
            if (session.getAttribute("langid") == null) {
                response.sendRedirect("index.jsp");
                return;
            }
            session.removeAttribute("DSMA");
            session.removeAttribute("DSNMA");
            session.removeAttribute("item");
            String action = request.getParameter("action");
            int langid = (Integer) session.getAttribute("langid");
            if (action.equals("Show")) {
                String maquyen = "48";
                NhanVien nv = new NhanVien();
                nv = (NhanVien) session.getAttribute("nv");
                if (NhanVien_Model.CheckQuyen(Integer.parseInt(maquyen), nv.getMaNV())) {
                    String item = request.getParameter("item");
                    KhuVuc_Model kvm = new KhuVuc_Model();
                    Vector vDSKV = new Vector();
                    vDSKV = kvm.LayDSKVTaoBan(langid);
                    Ban_Model bm = new Ban_Model();
                    Vector vDSBan = new Vector();
                    vDSBan = bm.MapDB("1");
                    DatBan_Model dbm = new DatBan_Model();
                    Vector vDSDB = new Vector();
                    vDSDB = dbm.LayDSDB();
                    request.setAttribute("DSKV", vDSKV);
                    request.setAttribute("DSBan", vDSBan);
                    request.setAttribute("DSDB", vDSDB);
                    request.setAttribute("makv", "1");
                    request.setAttribute("itemban", item);
                    request.setAttribute("itemdb", item);
                    RequestDispatcher rd = request.getRequestDispatcher("cashier/newreser.jsp");
                    rd.forward(request, response);
                }
                else{
                    response.sendRedirect("index.jsp");
                }
            } else if (action.equals("Map")) {
                String makv = request.getParameter("makv");
                String item = request.getParameter("item");
                Ban_Model bm = new Ban_Model();
                Vector v = new Vector();
                v = bm.MapDB(makv);
                request.setAttribute("DSBan", v);
                request.setAttribute("item", item);
                request.setAttribute("makv", makv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/maptablereserv.jsp");
                rd.forward(request, response);
            } else if (action.equals("SearchSeat")) {
                String makv = request.getParameter("makv");
                String item = request.getParameter("item");
                String soghe = request.getParameter("soghe");
                Ban_Model bm = new Ban_Model();
                Vector v = new Vector();
                v = bm.MapReserv(makv, soghe);
                request.setAttribute("DSBan", v);
                request.setAttribute("item", item);
                request.setAttribute("makv", makv);
                request.setAttribute("soghe", soghe);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/mapsearchreserv.jsp");
                rd.forward(request, response);
            } else if (action.equals("Add")) {
                String makv = request.getParameter("makv");
                String tenban = request.getParameter("tenban");
                String tenkh = request.getParameter("tenkh");
                String sokhach = request.getParameter("sokhach");
                String ngay = request.getParameter("ngay");
                String gio = request.getParameter("gio");
                String sodt = request.getParameter("sodt");
                int MaBan = DatBan_Model.LayMaBan(makv, tenban);
                DatBan_Model.ThemDatBan(MaBan, tenkh, sokhach, ngay, gio, sodt);
                int MaTTBan = Ban_Model.LayMaTTBan(MaBan);
                if(MaTTBan == 1){
                    Ban_Model.UpdateTTBan("7", Integer.toString(MaBan));
                }
                NhanVien nv = new NhanVien();
                nv = (NhanVien) session.getAttribute("nv");
                NhatKyHT_Model.GhiNhatKy(2, nv.getMaNV(), "reservation");
            } else if (action.equals("CheckBan")) {
                String makv = request.getParameter("makv");
                String tenban = request.getParameter("tenban");
                if (DatBan_Model.CheckBan(makv, tenban)) {
                    out.print("exist");
                } else {
                    out.print("error");
                }
            } else if (action.equals("ShowDB")) {
                String item = request.getParameter("item");
                //String makv = request.getParameter("makv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.LayDSDB();
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                //request.setAttribute("makv", makv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/listsearv.jsp");
                rd.forward(request, response);
            } else if (action.equals("CheckDatBan")) {
                String makv = request.getParameter("makv");
                String tenban = request.getParameter("tenban");
                String ngay = request.getParameter("ngay");
                String gio = request.getParameter("gio");
                int MaBan = DatBan_Model.LayMaBan(makv, tenban);
                if (DatBan_Model.CheckDatBan(MaBan, ngay, gio)) {
                    out.print("false");
                } else {
                    out.print("true");
                }
            }
            else if (action.equals("CheckDatBanUpdate")) {
                String madb = request.getParameter("madb");
                String makv = request.getParameter("makv");
                String tenban = request.getParameter("tenban");
                String ngay = request.getParameter("ngay");
                String gio = request.getParameter("gio");
                int MaBan = DatBan_Model.LayMaBan(makv, tenban);
                if (DatBan_Model.CheckDatBanUpdate(madb, MaBan, ngay, gio)) {
                    out.print("false");
                } else {
                    out.print("true");
                }
            }else if (action.equals("ShowDatBan")) {
                String maban = request.getParameter("maban");
                String makv = request.getParameter("makv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDB = new Vector();
                vDB = dbm.ShowDatBan(Integer.parseInt(maban));
                if (vDB.size() > 0) {
                    request.setAttribute("DB", vDB);
                    request.setAttribute("makv", makv);
                    RequestDispatcher rd = request.getRequestDispatcher("cashier/listdatban.jsp");
                    rd.forward(request, response);
                } else {
                    String item = request.getParameter("item");
                    Vector vDSDB = new Vector();
                    vDSDB = dbm.LayDSDB();
                    request.setAttribute("DSDB", vDSDB);
                    request.setAttribute("itemdb", item);
                    request.setAttribute("makv", makv);
                    RequestDispatcher rd = request.getRequestDispatcher("cashier/listsearv.jsp");
                    rd.forward(request, response);
                }
            } else if (action.equals("DeleteDB")) {
                String madb = request.getParameter("madb");
                String item = request.getParameter("item");                
                String MaDatBan[] = madb.split("-");
                int j = 0;
                while (j < MaDatBan.length) {                    
                    int MaBan = DatBan_Model.LayMaBanOld(Integer.parseInt(MaDatBan[j]));
                    DatBan_Model.DeleteDB(MaDatBan[j]);
                    int MaTTBan = Ban_Model.LayMaTTBan(MaBan);
                    if(MaTTBan == 7){
                        Ban_Model.UpdateTTBan("1", Integer.toString(MaBan));
                    }
                    j = j + 1;
                }
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.LayDSDB();
                NhanVien nv = new NhanVien();
                nv = (NhanVien) session.getAttribute("nv");
                NhatKyHT_Model.GhiNhatKy(4, nv.getMaNV(), "reservation");
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);                
                RequestDispatcher rd = request.getRequestDispatcher("cashier/listsearv.jsp");
                rd.forward(request, response);
            } else if (action.equals("DetailDB")) {
                String madb = request.getParameter("madb");
                String maban = request.getParameter("maban");
                DatBan_Model dbm = new DatBan_Model();
                Vector DB = new Vector();
                DB = dbm.Detail(madb);
                int MaKV = Ban_Model.LayMaKV(maban);
                String x = Integer.toString(MaKV);
                KhuVuc_Model kvm = new KhuVuc_Model();
                Vector vKhuVuc = new Vector();
                vKhuVuc = kvm.LayDSKVDB(MaKV, langid);
                request.setAttribute("DB", DB);
                request.setAttribute("DSKV", vKhuVuc);
                request.setAttribute("madb", madb);
                request.setAttribute("makv", x);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/detailresver.jsp");
                rd.forward(request, response);
            } else if (action.equals("UpdateReserv")) {
                String madb = request.getParameter("madb");
                String makv = request.getParameter("makv");
                String tenban = request.getParameter("tenban");
                String tenkh = request.getParameter("tenkh");
                String sokhach = request.getParameter("sokhach");
                String ngay = request.getParameter("ngay");
                String gio = request.getParameter("gio");
                String sodt = request.getParameter("sodt");
                int MaBan = DatBan_Model.LayMaBan(makv, tenban);
                int MaBan_old = DatBan_Model.LayMaBanOld(Integer.parseInt(madb));
                DatBan_Model.UpdateReserv(madb, MaBan, tenkh, sokhach, ngay, gio, sodt);
                Ban_Model.UpdateTTBan("7", Integer.toString(MaBan));
                if(MaBan_old != MaBan){
                    Ban_Model.UpdateTTBan("1", Integer.toString(MaBan_old));
                }
                NhanVien nv = new NhanVien();
                nv = (NhanVien) session.getAttribute("nv");
                NhatKyHT_Model.GhiNhatKy(3, nv.getMaNV(), "reservinfo");
            } else if (action.equals("CheckDate")) {
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                if(tungay.equals("") && denngay.equals("")){
                    out.print("true");
                }
                else{
                    if (DatBan_Model.CheckDate(tungay, tugio, denngay, dengio)) {
                        out.print("true");
                    } else {
                        out.print("false");
                    }
                }
            } else if (action.equals("SearchDB")) {
                String tenkv = request.getParameter("tenkv");
                String tenban = request.getParameter("tenban");
                String kh = request.getParameter("kh");
                String sodt = request.getParameter("sodt");
                String sokhach = request.getParameter("sokhach");
                String item = request.getParameter("item");
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                DatBan_Model nkm = new DatBan_Model();
                Vector v = new Vector();
                v = nkm.SearchDB(tungay, tugio, denngay, dengio, tenkv, tenban, kh, sodt, sokhach, langid);
                request.setAttribute("DSDB", v);
                request.setAttribute("itemdb", item);
                request.setAttribute("tenkv", tenkv);
                request.setAttribute("tenban", tenban);
                request.setAttribute("kh", kh);
                request.setAttribute("sodt", sodt);
                request.setAttribute("sokhach", sokhach);
                request.setAttribute("item", item);
                request.setAttribute("tungay", tungay);
                request.setAttribute("tugio", tugio);
                request.setAttribute("denngay", denngay);
                request.setAttribute("dengio", dengio);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssearchreserv.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortNgayGioDB")) {
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortNgayGioDB(langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "1");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortKVDB")) {
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortKVDB(langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "2");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortTenBanDB")) {
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortTenBanDB(langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "3");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortKHDB")) {
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortKHDB(langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "4");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortDTDB")) {
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortDTDB(langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "5");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortSoKhachDB")) {
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortSoKhachDB(langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "6");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortSearchNgayGioDB")) {
                String tenkv = request.getParameter("tenkv");
                String tenban = request.getParameter("tenban");
                String kh = request.getParameter("kh");
                String sodt = request.getParameter("sodt");
                String sokhach = request.getParameter("sokhach");
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortSearchNgayGioDB(tungay, tugio, denngay, dengio, tenkv, tenban, kh, sodt, sokhach, langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "1");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                request.setAttribute("tenkv", tenkv);
                request.setAttribute("tenban", tenban);
                request.setAttribute("kh", kh);
                request.setAttribute("sodt", sodt);
                request.setAttribute("sokhach", sokhach);
                request.setAttribute("tungay", tungay);
                request.setAttribute("tugio", tugio);
                request.setAttribute("denngay", denngay);
                request.setAttribute("dengio", dengio);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortsearchdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortSearchKVDB")) {
                String tenkv = request.getParameter("tenkv");
                String tenban = request.getParameter("tenban");
                String kh = request.getParameter("kh");
                String sodt = request.getParameter("sodt");
                String sokhach = request.getParameter("sokhach");
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortSearchKVDB(tungay, tugio, denngay, dengio, tenkv, tenban, kh, sodt, sokhach, langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "2");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                request.setAttribute("tenkv", tenkv);
                request.setAttribute("tenban", tenban);
                request.setAttribute("kh", kh);
                request.setAttribute("sodt", sodt);
                request.setAttribute("sokhach", sokhach);
                request.setAttribute("tungay", tungay);
                request.setAttribute("tugio", tugio);
                request.setAttribute("denngay", denngay);
                request.setAttribute("dengio", dengio);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortsearchdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortSearchTenBanDB")) {
                String tenkv = request.getParameter("tenkv");
                String tenban = request.getParameter("tenban");
                String kh = request.getParameter("kh");
                String sodt = request.getParameter("sodt");
                String sokhach = request.getParameter("sokhach");
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortSearchTenBanDB(tungay, tugio, denngay, dengio, tenkv, tenban, kh, sodt, sokhach, langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "3");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                request.setAttribute("tenkv", tenkv);
                request.setAttribute("tenban", tenban);
                request.setAttribute("kh", kh);
                request.setAttribute("sodt", sodt);
                request.setAttribute("sokhach", sokhach);
                request.setAttribute("tungay", tungay);
                request.setAttribute("tugio", tugio);
                request.setAttribute("denngay", denngay);
                request.setAttribute("dengio", dengio);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortsearchdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortSearchKHDB")) {
                String tenkv = request.getParameter("tenkv");
                String tenban = request.getParameter("tenban");
                String kh = request.getParameter("kh");
                String sodt = request.getParameter("sodt");
                String sokhach = request.getParameter("sokhach");
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortSearchKHDB(tungay, tugio, denngay, dengio, tenkv, tenban, kh, sodt, sokhach, langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "4");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                request.setAttribute("tenkv", tenkv);
                request.setAttribute("tenban", tenban);
                request.setAttribute("kh", kh);
                request.setAttribute("sodt", sodt);
                request.setAttribute("sokhach", sokhach);
                request.setAttribute("tungay", tungay);
                request.setAttribute("tugio", tugio);
                request.setAttribute("denngay", denngay);
                request.setAttribute("dengio", dengio);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortsearchdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortSearchDTDB")) {
                String tenkv = request.getParameter("tenkv");
                String tenban = request.getParameter("tenban");
                String kh = request.getParameter("kh");
                String sodt = request.getParameter("sodt");
                String sokhach = request.getParameter("sokhach");
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortSearchDTDB(tungay, tugio, denngay, dengio, tenkv, tenban, kh, sodt, sokhach, langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "5");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                request.setAttribute("tenkv", tenkv);
                request.setAttribute("tenban", tenban);
                request.setAttribute("kh", kh);
                request.setAttribute("sodt", sodt);
                request.setAttribute("sokhach", sokhach);
                request.setAttribute("tungay", tungay);
                request.setAttribute("tugio", tugio);
                request.setAttribute("denngay", denngay);
                request.setAttribute("dengio", dengio);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortsearchdatban.jsp");
                rd.forward(request, response);
            } else if (action.equals("SortSearchSoKhachDB")) {
                String tenkv = request.getParameter("tenkv");
                String tenban = request.getParameter("tenban");
                String kh = request.getParameter("kh");
                String sodt = request.getParameter("sodt");
                String sokhach = request.getParameter("sokhach");
                String tungay = request.getParameter("tungay");
                String tugio = request.getParameter("tugio");
                String denngay = request.getParameter("denngay");
                String dengio = request.getParameter("dengio");
                String item = request.getParameter("item");
                String order = request.getParameter("order");
                String sort = request.getParameter("sort");
                String sortkv = request.getParameter("sortkv");
                DatBan_Model dbm = new DatBan_Model();
                Vector vDSDB = new Vector();
                vDSDB = dbm.SortSearchSoKhachDB(tungay, tugio, denngay, dengio, tenkv, tenban, kh, sodt, sokhach, langid, order);
                request.setAttribute("DSDB", vDSDB);
                request.setAttribute("itemdb", item);
                request.setAttribute("order", order);
                request.setAttribute("test", "6");
                request.setAttribute("sort", sort);
                request.setAttribute("sortkv", sortkv);
                request.setAttribute("tenkv", tenkv);
                request.setAttribute("tenban", tenban);
                request.setAttribute("kh", kh);
                request.setAttribute("sodt", sodt);
                request.setAttribute("sokhach", sokhach);
                request.setAttribute("tungay", tungay);
                request.setAttribute("tugio", tugio);
                request.setAttribute("denngay", denngay);
                request.setAttribute("dengio", dengio);
                RequestDispatcher rd = request.getRequestDispatcher("cashier/rssortsearchdatban.jsp");
                rd.forward(request, response);
            }
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
